package com.soFun.controller;

import com.soFun.service.AiService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * AI控制器，提供AI相关的API端点
 */
@RestController
@RequestMapping("/ai")
@RequiredArgsConstructor
public class AiController {

    private final AiService aiService;

    /**
     * 聊天接口
     * @param message 用户消息
     * @return 包含AI回复的Map
     */
    @PostMapping("/chat")
    public Map<String, Object> chat(@RequestBody Map<String, String> requestBody) {
        String message = requestBody.get("message");
        String response = aiService.chat(message);
        
        Map<String, Object> result = new HashMap<>();
        result.put("status", "success");
        result.put("message", response);
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }
    
    /**
     * 生成摘要接口
     * @param requestBody 包含原文本的请求体
     * @return 包含摘要的Map
     */
    @PostMapping("/summary")
    public Map<String, Object> generateSummary(@RequestBody Map<String, String> requestBody) {
        String text = requestBody.get("text");
        String summary = aiService.generateSummary(text);
        
        Map<String, Object> result = new HashMap<>();
        result.put("status", "success");
        result.put("summary", summary);
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }
    
    /**
     * 翻译接口
     * @param requestBody 包含原文本和目标语言的请求体
     * @return 包含翻译结果的Map
     */
    @PostMapping("/translate")
    public Map<String, Object> translate(@RequestBody Map<String, String> requestBody) {
        String text = requestBody.get("text");
        String targetLanguage = requestBody.get("targetLanguage");
        String translation = aiService.translate(text, targetLanguage);
        
        Map<String, Object> result = new HashMap<>();
        result.put("status", "success");
        result.put("translation", translation);
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }
} 